function Tree(contextPath,divContainer){
	View.apply(this,arguments);
	this.displayField = "NAMETEXT";
	this.hasChildrenField = "HASCHILDREN";
	this.selectedTreeNodeId = null;
	this.isShowCheckbox = "0";
	this.lastRequestObject = null;
	
	this.beforeRefresh = function(){
		this.divContainer.className = "checktree";
		return buildTree(this.getDataArray(),this.displayField,this.hasChildrenField,this.isShowCheckbox,false);
	};
	
	this.loadSubTreeNodes = function(container){
		if(container){
			container.innerHTML = container.innerHTML+buildTree(this.getDataArray(),this.displayField,this.hasChildrenField,this.isShowCheckbox,true);
		}
	};
	
	var buildTree = function(nodeArray,displayField,hasChildrenField,isShowCheckbox,hasParent){
		var getNodeStyle = function(curIndex,lastIndex,hasChildren,hasParent){
			var styleName = "node";
			if(hasChildren>"0"){
				styleName = "plus";
			}
			if(curIndex===0&&!hasParent){
				styleName += "-first";
			}
			if(curIndex==lastIndex){
				styleName += "-last";
			}
			return styleName;
		};
		var treeHtmlArray = ['<ul>'];
		var length = nodeArray.length;
		for(var i=0;i<length;i++){
			var attributeArray = [];
			for(var attrName in nodeArray[i]){
				attributeArray.push(attrName+'="'+nodeArray[i][attrName]+'"');
			}
			var styleName = getNodeStyle(i,length-1,nodeArray[i][hasChildrenField],hasParent);
			treeHtmlArray.push('<li id="'+window["Comm"].randomString()+'" class="'+styleName+'" '+attributeArray.join(" ")+'><span>');
			if(isShowCheckbox==="1"){
				treeHtmlArray.push('<input type="checkbox" onfocus="this.blur()">&nbsp;');
			}
			treeHtmlArray.push('<font>'+(nodeArray[i][displayField+"TEXT"]||nodeArray[i][displayField])+'</font></span></li>');
		}
		treeHtmlArray.push('</ul>');
		return treeHtmlArray.join('');
	};	
}

Tree.prototype = new View();

Tree.prototype.handleMouseOverEvent0 = function(evt){
	var handleObject = evt.srcElement;
	if(handleObject.tagName=="FONT"&&handleObject.parentElement.parentElement.id!=this.selectedTreeNodeId){
		handleObject.style.color = "white";
		handleObject.style.backgroundColor = "darkblue";
		handleObject.style.cursor = "hand";
	}
};

Tree.prototype.handleMouseOutEvent0 = function(evt){
	var handleObject = evt.srcElement;
	if(handleObject.tagName=="FONT"&&handleObject.parentElement.parentElement.id!=this.selectedTreeNodeId){
		handleObject.style.color = "black";
		handleObject.style.backgroundColor = "transparent";
	}
};

Tree.prototype.handleClickEvent0 = function(evt){ 
	var handleObject = evt.srcElement;
	if(handleObject.tagName=="LI"){
		var styleName = handleObject.className;
		if(styleName.indexOf("plus")>-1){
			handleObject.className = styleName.replace("plus","minus");
			if(handleObject.children.length>1){
				handleObject.children[1].style.display = "";
			}else{
				this.lastRequestObject.requestAction.condition = "PARENTID="+handleObject.FUNID;
				this.dataModel = window["Comm"].sendRequest(this.contextPath,this.lastRequestObject);
				this.loadSubTreeNodes(handleObject);
			}
		}else{
			handleObject.className = styleName.replace("minus","plus");
			var ulArray = handleObject.getElementsByTagName("UL");
			if(ulArray.length>0){
				ulArray[0].style.display = "none";
			}
		}
		return true;
	}else if(handleObject.tagName=="FONT"){
		var selectedTreeNode = document.getElementById(this.selectedTreeNodeId);
		if(selectedTreeNode){
			var fontObject = selectedTreeNode.firstChild.getElementsByTagName("FONT")[0];
			fontObject.style.color = "black";
			fontObject.style.backgroundColor = "transparent";
		}
		handleObject.style.color = "white";
		handleObject.style.backgroundColor = "darkblue";
		this.selectedTreeNodeId = handleObject.parentElement.parentElement.id;
		return true;
	}else if(handleObject.tagName=="INPUT"){
	}
};